﻿namespace Cos.Core.NHibernate.Util
{
    using System.Linq;

    using Cos.Core.Model.Blog;
    using Cos.Core.Model.Common;

    /// <summary>
    /// The Converter class of BlogModel.
    /// </summary>
    public static class BlogModelConverter
    {
        /// <summary>
        /// Converts BlogDataModel to Blog object.
        /// </summary>
        /// <param name="blogDataModel">The blog data model object.</param>
        /// <param name="culture">The culture object.</param>
        /// <returns>The Converted Blog object.</returns>
        public static Blog ToBlog(this BlogDataModel blogDataModel, string cultureCode)
        {
            var blog = new Blog();

            blog.Id = blogDataModel.Id;
            blog.CreationDate = blogDataModel.CreationDate;
            blog.OwnerId = blogDataModel.OwnerId.ToString();
            blog.OwnerFirstName = blogDataModel.OwnerFirstName;
            blog.OwnerLastName = blogDataModel.OwnerLastName;
            blog.CultureCode = cultureCode;

            return blog;
        }

        /// <summary>
        /// Converts ArticleDataModel object to Article object.
        /// </summary>
        /// <param name="articleDataModel">The article data model object.</param>
        /// <param name="culture">The culture object.</param>
        /// <returns>The converted Article object.</returns>
        public static Article ToArticle(this ArticleDataModel articleDataModel, string cultureCode)
        {
            var article = new Article();

            article.Id = articleDataModel.Id;
            article.BlogId = articleDataModel.BlogId;
            article.CreationDate = articleDataModel.CreationDate;
            article.CultureCode = cultureCode;

            return article;
        }

        /// <summary>
        /// Converts CommentDataModel object to Comment object.
        /// </summary>
        /// <param name="commentDataModel">The comment data model object.</param>
        /// <returns>The converted Comment object.</returns>
        public static Comment ToComment(this CommentDataModel commentDataModel)
        {
            var comment = new Comment();

            comment.Id = commentDataModel.Id;
            comment.ArticleId = commentDataModel.ArticleCultureId;
            comment.AuthorId = commentDataModel.AuthorId;
            comment.AuthorFirstName = commentDataModel.AuthorFirstName;
            comment.AuthorLastName = commentDataModel.AuthorLastName;
            comment.CreationDate = commentDataModel.CreationDate;
            comment.LastModified = commentDataModel.LastModified;
            comment.Text = commentDataModel.Text;
            comment.Title = commentDataModel.Title;

            return comment;
        }

        /// <summary>
        /// Toes the tag.
        /// </summary>
        /// <param name="blogArticleTagDataModel">The blog article tag data model.</param>
        /// <param name="culture">The culture object.</param>
        /// <returns>The converted Tag object.</returns>
        public static Tag ToTag(this BlogArticleTagDataModel blogArticleTagDataModel, string cultureCode)
        {
            var tag = new Tag();

            tag.Name = blogArticleTagDataModel.TagName;
            tag.CultureCode = cultureCode;

            return tag;
        }
    }
}
